//
//  BezierViewController.m
//  DebugDemo
//
//  Created by XFB on 2019/5/13.
//  Copyright © 2019 ZhouCheng. All rights reserved.
//  曲线图

#import "BezierViewController.h"
#import "BezierView.h"
#import "BarView.h"

@interface BezierViewController () <UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) BezierView *bezierView1;  // 直线
@property (nonatomic, strong) BezierView *bezierView2;  // 曲线

@property (nonatomic, strong) BezierView *bezierView6;  // 曲线
@property (nonatomic, strong) BezierView *bezierView7;  // 曲线


@property (nonatomic, strong) BezierView *bezierView3;  // 柱状图
@property (nonatomic, strong) BezierView *bezierView4;  // 饼状图

@property (nonatomic, strong) BarView *bezierView5;  // 饼状图

@property (nonatomic, strong) NSMutableArray *x_names;  // x轴坐标值数组
@property (nonatomic, strong) NSMutableArray *y_values; // y轴坐标值数组

@end

@implementation BezierViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];    
    [self.view addSubview:self.scrollView];
    
//    self.bezierView1 = [[BezierView alloc] initWithFrame:CGRectMake(30, 30, ScreenW-60, ScreenH/2-120)];
//    [self.scrollView addSubview:self.bezierView1];
    
    self.bezierView5 = [[BarView alloc] initWithFrame:CGRectMake(30, 30, ScreenW-45, ScreenH/2-120)];
    [self.scrollView addSubview:self.bezierView5];
    self.bezierView5.x_names = @[@"星期1", @"星2", @"星3", @"星4", @"星5", @"星6", @"期7", @"期1", @"期2"];
    self.bezierView5.y_values = @[@"20", @"40", @"20", @"50", @"30", @"90", @"30", @"100", @"70"];
    [self.bezierView5 show];

    self.bezierView2 = [[BezierView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.bezierView5.frame) + 50, ScreenW-60, ScreenH/2-60)];
    [self.scrollView addSubview:self.bezierView2];
    
    self.bezierView6 = [[BezierView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.bezierView5.frame) + 50, ScreenW-60, ScreenH/2-60)];
    [self.scrollView addSubview:self.bezierView6];
    
    self.bezierView7 = [[BezierView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.bezierView5.frame) + 50, ScreenW-60, ScreenH/2-60)];
    [self.scrollView addSubview:self.bezierView7];
    
    self.bezierView3 = [[BezierView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.bezierView2.frame) + 50, ScreenW-60, ScreenH/2-60)];
    [self.scrollView addSubview:self.bezierView3];
    
    self.bezierView4 = [[BezierView alloc] initWithFrame:CGRectMake(30, CGRectGetMaxY(self.bezierView3.frame) + 50, ScreenW-60, ScreenH/2-60)];
    [self.scrollView addSubview:self.bezierView4];

    CGColorRef startColor1 = RGBA(239, 152, 0, 0.8).CGColor;
    CGColorRef endColor1 = RGBA(239, 152, 0, 0.2).CGColor;
    NSArray *gradientColors1 = @[(__bridge id)startColor1, (__bridge id)endColor1];
    
    /// 画直线
    [self.bezierView1 drawLineViewWithX_Values_Names:self.x_names y_values:self.y_values lineType:LineType_Straight gradientColors:gradientColors1];
    [self.bezierView1 drawBarChartViewWithX_Values_Names:self.x_names y_values:self.y_values];

    CGColorRef startColor2 = RGBA(125, 189, 237, 0.8).CGColor;
    CGColorRef endColor2 = RGBA(139, 152, 0, 0.2).CGColor;
    NSArray *gradientColors2 = @[(__bridge id)startColor2, (__bridge id)endColor2];
    
    CGColorRef startColor3 = RGBA(29, 12, 150, 0.8).CGColor;
    CGColorRef endColor3 = RGBA(239, 152, 0, 0.2).CGColor;
    NSArray *gradientColors3 = @[(__bridge id)startColor3, (__bridge id)endColor3];
    
    /// 画曲线
    [self.bezierView2 drawLineViewWithX_Values_Names:self.x_names y_values:self.y_values lineType:LineType_Curve gradientColors:gradientColors1];
//    [self.bezierView6 drawLineViewWithX_Values_Names:self.x_names y_values:[NSMutableArray arrayWithArray:@[@60, @80, @90, @20, @40, @80, @10, @50, @70]] lineType:LineType_Curve gradientColors:gradientColors2];
//    [self.bezierView7 drawLineViewWithX_Values_Names:self.x_names y_values:[NSMutableArray arrayWithArray:@[@10, @50, @30, @60, @80, @10, @70, @30, @70]] lineType:LineType_Curve gradientColors:gradientColors3];

    
    NSMutableArray *array = @[].mutableCopy;
    NSMutableArray *array1 = @[].mutableCopy;

    [self.x_names enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if ([obj isEqualToString:@"1"]) {
            [array addObject:obj];
        } else {
            [array1 addObject:obj];
        }
    }];
    
    /// 柱状图
    [self.bezierView3 drawBarChartViewWithX_Values_Names:self.x_names y_values:self.y_values];
    /// 饼状图
    [self.bezierView4 drawPieChartViewWithX_Values_Names:self.x_names y_values:self.y_values];
}

/// x轴坐标
- (NSMutableArray *)x_names
{
    if (!_x_names) {
//        _x_names = [NSMutableArray arrayWithArray:@[@"语文", @"数学", @"英语", @"物理", @"化学", @"生物", @"政治", @"历史", @"地理"]];
        _x_names = [NSMutableArray arrayWithArray:@[@"语文", @"数学", @"英语", @"物理", @"化学"]];
    }
    return _x_names;
}

- (NSMutableArray *)y_values
{
    if (!_y_values) {
//        _y_values = [NSMutableArray arrayWithArray:@[@20, @40, @20, @50, @30, @90, @30, @100, @70]];
        _y_values = [NSMutableArray arrayWithArray:@[@20, @40, @20, @50, @30]];
    }
    return _y_values;
}

- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenW, ScreenH-NavBarHeight-BottomHeight)];
        _scrollView.delegate = self;
        _scrollView.backgroundColor = [UIColor whiteColor];
        _scrollView.contentSize = CGSizeMake(ScreenW, ScreenH*2.5);
    }
    return _scrollView;
}

@end
